package com.example.design.shejimoshi.action.state.状态机实现方式一分支逻辑法;

import com.example.design.shejimoshi.action.state.enums.State;
import lombok.Getter;

/**
 * @Description TODO
 * @date 2022/11/2 10:42
 * @Author liuzhihui
 * @Version 1.0
 */
@Getter
public class MarioStateMachine {
    private int score;

    private State currentState;

    /**
     * 初始为小马里奥
     */
    public MarioStateMachine() {
        this.score = 0;
        this.currentState = State.SMALL;
    }

    /**
     * 获取蘑菇，变身超级马里奥,加100分
     */
    public void obtainMushRoom() {
        if (currentState.equals(State.SMALL)) {
            currentState = State.SUPER;
            this.score += 100;
        }
    }

    /**
     * 获取斗篷，变成斗篷马里奥，加200分
     */
    public void obtainCape() {
        if (currentState.equals(State.SMALL) || currentState.equals(State.SUPER)) {
            this.currentState = State.CAPE;
            this.score += 200;
        }
    }

    /**
     * 获取火焰，变身火焰马里奥，加300分
     */
    public void obtainFireFlower() {
        if (currentState.equals(State.SMALL) || currentState.equals(State.SUPER)) {
            this.currentState = State.FIRE;
            this.score += 300;
        }
    }

    /**
     * 遇见怪兽，变成小马里奥，并减分
     */
    public void meetMonster() {
        if (currentState.equals(State.SUPER)) {
            this.currentState = State.SMALL;
            this.score -= 100;
            return;
        }
        if (currentState.equals(State.CAPE)) {
            this.currentState = State.SMALL;
            this.score -= 200;
            return;
        }
        if (currentState.equals(State.FIRE)) {
            this.currentState = State.SMALL;
            this.score -= 300;
            return;
        }
    }

}
